package com.winit.core.configuration;

import com.winit.common.util.JSONFileUtil;
import com.winit.core.ci.vcs.VCS;
import com.winit.core.ci.vcs.exception.VCSException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by wangjian on 16/8/1.
 */
public class ConfigRepositoryEditor extends ConfigRepository{

    private static final Logger logger = LoggerFactory.getLogger(ConfigRepositoryEditor.class);

    /**
     * 工程的configProjectName
     * configProjectName为空时,传工程的projectName
     */
    private String projectName;
    private String envName;
    /**
     * 配置文件相对工程根目录路径
     */
    private String configPath;

    public ConfigRepositoryEditor(String rootPath,String projectName, String envName, String configPath) {
        super(rootPath);
        this.projectName = projectName;
        this.envName = envName;
        this.configPath = configPath;
    }

    /**
     * 保存配置文件
     * @param content
     * @return
     */
    public boolean saveFile(String content) throws Exception{
        String path = super.getConfigURI(projectName, envName, configPath);
        return JSONFileUtil.saveFile(path, content);
    }

    public boolean commitCode(VCS vcs) throws VCSException{
        return vcs.doCommit();
    }

}
